package com.team2.outpatient_sys.web;

import com.team2.outpatient_sys.pojo.Patient;
import com.team2.outpatient_sys.pojo.Result;
import com.team2.outpatient_sys.service.PatientService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/patients")
public class PatientController {
    @Autowired
    private PatientService patientService;

    @PutMapping("/add")
    public Result add(@RequestBody Patient patient) {
        Result result = new Result();
        if (patientService.add(patient)) {
            result.setCode(200);
            result.setMsg("添加成功");
        } else {
            result.setCode(500);
            result.setMsg("添加失败");
        }
        return result;
    }

    @PostMapping("/update")
    public Result update(@RequestBody Patient patient) {
        Result result = new Result();
        if (patientService.update(patient)) {
            result.setCode(200);
            result.setMsg("修改成功");
        } else {
            result.setCode(500);
            result.setMsg("修改失败");
        }
        return result;
    }
}
